/*
day245
2020.4.29
*/
#include<iostream>
#include<stack>
using namespace std;

struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
	stack<TreeNode *> sta;
	TreeNode* next()
	{
		TreeNode *root=sta.top();
		while(root)
		{
			sta.push(root);
			root=root->left;
		 } 
		
		
		TreeNode *res=sta.top();
		sta.pop();
		sta.push(res->right);
		return res;
	}
	
	
    TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {
		this->sta.push(root);
		while(1)
		{
			TreeNode *tem=next();
			if(tem==p)
			{
				break;
			}
		}
		return next();
    }
};

int main()
{
	return 0;
}
